﻿using Abp.Runtime.Session;
using Abp.Timing.Timezone;
using Camc.Quality.DataExporting.Excel.EpPlus;
using Camc.Quality.Dto;
using Camc.Quality.Storage;
using Camc.Quality.TrepanningManager.BomAnalyseDto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Camc.Quality.TrepanningManager.ArrowPresetSearch.ArrowPresetSearchInterface
{
   public class ArrowPresetSearchExportToExcel: EpPlusExcelExporterBase, IArrowPresetSearchExportToExcel
    {
        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;

        public ArrowPresetSearchExportToExcel(
            ITimeZoneConverter timeZoneConverter,
            // IAbpSession abpSession,
            ITempFileCacheManager tempFileCacheManager)
            : base(tempFileCacheManager)
        {
            _timeZoneConverter = timeZoneConverter;
            // _abpSession = abpSession;
        }
        public string ExportToFile(List<BomAnalyseContentDto> userListDtos)
        {
            return CreateExcelPackageLocal(
               "整箭预配套.xlsx",
               excelPackage =>
               {
                   var sheet = excelPackage.Workbook.Worksheets.Add(L("整箭预配套明细"));
                   sheet.OutLineApplyStyle = true;

                   AddHeader(
                       sheet,
                       L("物料图号"),
                       L("物料名称"),
                       L("规格"),
                       L("物料类别"),
                       L("细类"),
                       L("单位"),
                       L("整箭用量"),
                       L("可用库存数量"),
                       L("预配套数量"),
                       L("缺料数量"),
                       L("出库数量"),
                       L("预配套状态")
                       );

                   AddObjects(
                       sheet, 2, userListDtos,
                       _ => _.MaterialNo,
                       _ => _.MaterialName,
                       _ => _.Module,
                       _ => _.MaterialTypeName,
                       _ => _.MaterialCategoryName,
                       _ => _.UnitName,
                       _ => _.BomDosageTotalAmount,
                       _ => _.UsableQuantityStock,
                       _ => _.PreSuiteStock,
                       _ => _.StarvingStockAll,
                       _ => _.DeliveryStockAll,
                       _ => _.PreSuiteStatusName
                       );
                    //Formatting cells
                   // var creationTimeColumn = sheet.Column(7);
                   //creationTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd HH:mm:ss";

                   for (var i = 1; i <=11; i++)
                   {
                       sheet.Column(i).AutoFit();
                   }
               });
        }
    }

}
